<!DOCTYPE html>
<html>
<head>
	<meta content="text/html;charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
	<meta http-equiv ="Pragma" content = "no-cache"/>
	<meta http-equiv="Cache-Control" content="no cache" />
	<meta http-equiv="Expires" content="0" />
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
	<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
	<meta name="apple-mobile-web-app-capable" content="yes"/>
	<meta name="format-detection" content="telephone=no"/>
	<script src="https://cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
	<link href="https://cdn.bootcss.com/pace/1.0.2/themes/pink/pace-theme-flash.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="../../plugins/layui/css/layui.css" media="all"/>
	<link rel="stylesheet" type="text/css" href="../../css/fs.css" media="all"/>
	<script type="text/javascript" src="../../plugins/jquery/jquery.min.js"></script>
	<script type="text/javascript" src="../../plugins/home/common.js"></script>
	<script src="https://cdn.bootcss.com/layer/2.3/layer.js"></script>
	<script src="https://www.layuicdn.com/layui/layui.js"></script>
	<script src="https://cdn.bootcss.com/axios/0.19.0/axios.min.js"></script>
	<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
	<script type="text/javascript" src="../../scripts/home/yunhetong.js"></script>
	<script type="text/javascript" src="../../scripts/home/magerIndcInfo.js"></script>
</head>
<body>
<form class="layui-form" >
	<div  id="app">
		<div class="layui-form-item">
			<label class="layui-form-label">管理人名称</label>
			<div class="layui-input-block">
				<div class="layui-form-mid layui-word-aux">{{custNm}}</div>
			</div>
		</div>
		<div class="layui-form-item">
			<input type="hidden" id="custNm" name="custNm" v-model="custNm" title="管理人">
			<input type="hidden" id="crmMagerId" name="crmMagerId"  v-model="crmMagerId" title="CRM对应管理人ID">
			<label class="layui-form-label">证件类型</label>
			<div class="layui-input-block">
				<input type="hidden" id="certifyType" name="certifyType" v-model="certTyp"/>
				<select name="cardType" lay-filter="cardTypeFilter"   lay-verify="required" v-model="certTyp">
					<option value=""></option>
					<option :value="item.cKeyValue"  v-for="item in cardTypeList">{{item.cCaption}}</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">证件号码</label>
			<div class="layui-input-block">
				<input type="text"  v-model="certNo" lay-verify="required|cardNumber" autocomplete="off" class="layui-input" maxlength="18">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">手机号码</label>
			<div class="layui-input-block">
				<input type="tel" name="mobile" v-model="mobile" lay-verify="required|phone|number" autocomplete="off" class="layui-input" maxlength="11">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<a class="layui-btn" lay-submit="" lay-filter="demo1">修改</a>
			</div>
		</div>
	</div>
</form>

<script>
var caCustId=getQueryVariable("caCustId");
var custNm=decodeURI(getQueryVariable("custNm"));
var certTyp=getQueryVariable("certTyp");
var certNo=getQueryVariable("certNo");
var mobileNo=getQueryVariable("mobileNo");
var crmMagerId=getQueryVariable("crmMagerId");
    layui.use('form', function(){
        var form = layui.form;
        //监听提交
        form.on('submit(demo1)', function(data){
            var custNm=data.field.custNm;//企业名称
            var certifyType=$("#certifyType").val();//企业相关证件
            var certifyNum=data.field.cardNo;//认证号码
            var phoneNo=data.field.mobile;//企业类型用户的手机号
            var result=queryUserNo(certifyNum);
            var crmMagerId=$("#crmMagerId").val();
            var caCustId="";//客户ID
            if(result.code==200){
                caCustId=result.data[0];
                caCustId=JSON.stringify(caCustId);
                caCustId=caCustId.substring(1,caCustId.length-1);
                caCustId=caCustId.split(":")[0];
            }else{
                //没有返回用户id，则调用企业用户
                var result=createCompanyUser(custNm,certifyType,certifyNum,phoneNo);
                console.log("createCompanyUser..................返回结果"+JSON.stringify(result));
                if(result.code==20209){
                    messageInfo(result.msg);
                    return false;
                }else{
                    caCustId=result.data.signerId;
                }
            }

            //插入表MAGER_INDC_INFO
            var idenUser=getCurrentLoginUser();
            addMagerIndcInfo(custNm,certifyType,certifyNum,phoneNo,crmMagerId,caCustId,idenUser);
        });
        //监听select
        form.on('select(cardTypeFilter)', function (data) {
            $("#certifyType").val(data.value);
        });
        //自定义校验规则
        form.verify({
            username: function(value, item){ //value：表单的值、item：表单的DOM对象
                if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
                    return '用户名不能有特殊字符';
                }
                if(/(^\_)|(\__)|(\_+$)/.test(value)){
                    return '用户名首尾不能出现下划线\'_\'';
                }
                if(/^\d+\d+\d$/.test(value)){
                    return '用户名不能全为数字';
                }
            }
            ,pass: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ],
            cardNumber:function(value,item){
                var type=$("#certifyType").val();
                alert("type===="+type);
                if(type==1||type==2){
                    if(value.length!=18){
                        return "证件号码格式错误";
                    }
                }else{
                    if(value.length!=9){
                        return "证件号码格式错误";
                    }
                }
            }
        });

    });
    var domain=getRootPath();
    new Vue({
        el: '#app',
        data () {
            return {
                cardTypeList:[],
                caCustId:caCustId,
                custNm: custNm,
                certTyp: certTyp,
                certNo: certNo,
                crmMagerId: crmMagerId,
                mobile: mobileNo
            }
        },
        mounted () {
            axios.post(domain+"/v1/cardType/get",{
                //firstName: 'Fred',        // 参数 firstName
                //lastName: 'Flintstone'    // 参数 lastName
            }).then(response => (this.cardTypeList = response.data.data))
        .catch(function (error) { // 请求失败处理
                console.log(error);
            });
        },method:{
            update:function(){
                alert(this.custNm+","+this.certTyp+","+this.certNo+","+this.mobile);

			}
		}
    })


</script>

</body>
</html>
